<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="90px"
  (onSearch)="queryData($event)"
  (onReset)="resetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-2">
  <div class="operation-wrap">
    <button
      nz-button
      nzType="primary"
      (click)="jumpPage(0)"
    >新增直降促销</button>
  </div>

  <div class="pagination-wrap-position table-wrap p-t-10">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="120px" nzLeft>ID</th>
          <th nzAlign="center" nzWidth="220px">名称</th>
          <th nzAlign="center" nzWidth="160px">类型</th>
          <th nzAlign="center" nzWidth="180px">适用品类</th>
          <th nzAlign="center" nzWidth="120px">适用用户</th>
          <th nzAlign="center" nzWidth="170px">开始时间</th>
          <th nzAlign="center" nzWidth="170px">结束时间</th>
          <th nzAlign="center" nzWidth="200px">备注</th>
          <th nzAlign="center" nzWidth="150px">状态</th>
          <th nzAlign="center" nzWidth="380px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- ID -->
          <td nzAlign="center" nzLeft>{{ data.id }}</td>
          <!-- 名称 -->
          <td nzAlign="center">{{ data.name || '-' }}</td>
          <!-- 类型 -->
          <td nzAlign="center">
            <div [ngSwitch]="data.type">
              <div *ngSwitchCase="1">满减</div>
              <div *ngSwitchCase="2">满折</div>
              <div *ngSwitchCase="3">多件折扣</div>
              <div *ngSwitchDefault>-</div>
            </div>
          </td>
          <!-- 适用品类 -->
          <td nzAlign="center">
            {{ categoryTypeFilter(data.containsTypes) }}
          </td>
          <!-- 适用用户 -->
          <td nzAlign="center">
            <div [ngSwitch]="data.userType">
              <div *ngSwitchCase="0">
                <nz-tag>不限制</nz-tag>
              </div>
              <div *ngSwitchCase="1">
                <nz-tag [nzColor]="'#87d068'">C端</nz-tag>
              </div>
              <div *ngSwitchCase="2">
                <nz-tag [nzColor]="'#2db7f5'">B端</nz-tag>
              </div>
              <div *ngSwitchDefault>-</div>
            </div>
          </td>
          <!-- 开始时间 -->
          <td nzAlign="center">{{ data.beginTime || '-' }}</td>
          <!-- 结束时间 -->
          <td nzAlign="center">{{ data.endTime || '-' }}</td>
          <!-- 备注 -->
          <td nzAlign="center">{{ data.remark || '-' }}</td>
          <!-- 状态 -->
          <td nzAlign="center">
            <span
              *ngIf="data?.status || data?.status == 0"
              [ngStyle]="{'color': data.status | customizedDescentStatus: 'color'}">
              {{ data.status | customizedDescentStatus: 'label' }}
            </span>
          </td>
          <!-- 操作 -->
          <td nzAlign="center" nzRight class="opreation-btns">
            <a
              nz-button
              nzSize="small"
              nzType="link"
              (click)="jumpPage(2, data)"
            >查看</a>

            <a
              *ngIf="[5].includes(data.status)"
              nz-button
              nzSize="small"
              nzType="link"
              (click)="jumpPage(1, data)"
            >编辑</a>

            <a
              nz-button
              nzSize="small"
              nzType="link"
              (click)="jumpPage(3, data)"
            >复制</a>

            <a
              *ngIf="[5].includes(data.status)"
              nz-button
              nzSize="small"
              nzType="link"
              nz-popconfirm
              nzPopconfirmTitle="确认发布?"
              (nzOnConfirm)="releaseItem(data)"
            >发布</a>

            <a
              *ngIf="[2].includes(data.status)"
              nz-button
              nzSize="small"
              nzType="link"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确定停止?"
              (nzOnConfirm)="stopDelActivity(data, 4)"
            >停止</a>

            <a
              *ngIf="[4].includes(data.status)"
              nz-button
              nzSize="small"
              nzType="link"
              nz-popconfirm
              nzPopconfirmTitle="确定启用?"
              (nzOnConfirm)="stopDelActivity(data, 1)"
            >启用</a>

            <a
              nz-button
              nzSize="small"
              nzType="link"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确认删除?"
              (nzOnConfirm)="stopDelActivity(data, 8)"
            >删除</a>

            <a
              *ngIf="[2, 3, 4].includes(data.status)"
              nz-button
              nzSize="small"
              nzType="link"
              (click)="showUserCouponModal(data)"
            >直降记录</a>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<!-- S 直降记录 -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [nzWidth]="1300"
  [(nzVisible)]="isUserVisible"
  [nzTitle]="'直降记录'"
  (nzOnCancel)="isUserVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <div class="modal-search-wrap">
        <!-- S search -->
        <app-search-bar
          [submitLoading]="userCouponTableParams.loading"
          [searchOptions]="userCouponSearch"
          labelFlex="90px"
          [xxlSize]="8"
          (onSearch)="couponQueryData($event)"
          (onReset)="couponResetData($event)"
        ></app-search-bar>
        <!-- E search -->
      </div>

      <div class="table-wrap p-t-10">
        <nz-table
          #userTable
          nzSize="small"
          nzShowSizeChanger
          nzShowQuickJumper
          nzBordered
          [nzFrontPagination]="false"
          [nzLoadingDelay]="100"
          [nzLoading]="userCouponTableParams.loading"
          [nzData]="userCouponTableParams.tableData"
          [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
          [nzTotal]="userCouponTableParams.total"
          [nzPageIndex]="userCouponTableParams.page"
          [nzPageSize]="userCouponTableParams.pageSize"
          [nzShowTotal]="totalTemplate2"
          (nzPageIndexChange)="recordIndexChange($event)"
          (nzPageSizeChange)="recordSizeChange($event)"
        >
          <thead>
            <tr>
              <th nzAlign="center">订单编号</th>
              <th nzAlign="center">订单状态</th>
              <th nzAlign="center">用户ID</th>
              <th nzAlign="center">应付金额</th>
              <th nzAlign="center">实付金额</th>
              <th nzAlign="center">优惠总额</th>
              <th nzAlign="center">本优惠金额</th>
              <th nzAlign="center">下单时间</th>
              <th nzAlign="center">付款时间</th>
            </tr>
          </thead>
  
          <tbody>
            <tr *ngFor="let data of userTable.data; let index = index;">
              <!-- 订单编号 -->
              <td nzAlign="center">{{ data.orderNum || '-' }}</td>
              <!-- 订单状态 -->
              <td nzAlign="center">
                <span
                  *ngIf="data?.status || data?.status == 0"
                  [ngStyle]="{'color': data.status | customizedOrderStatus: 'color'}">
                  {{ data.status | customizedOrderStatus: 'label' }}
                </span>
              </td>
              <!-- 用户ID -->
              <td nzAlign="center">
                <a
                  nz-button
                  nzType="link"
                  [disabled]="!data.userId"
                  target="_blank"
                  [routerLink]="['/customer/tabs', data.userId, 0]"
                >{{ data.userId }}</a>
              </td>
              <!-- 应付金额 -->
              <td nzAlign="center">{{ data.totalPrice || '0' }}</td>
              <!-- 实付金额 -->
              <td nzAlign="center">{{ data.realPrice || '0' }}</td>
              <!-- 优惠总额 -->
              <td nzAlign="center">{{ data.favorablePrice || '0' }}</td>
              <!-- 本优惠金额 -->
              <td nzAlign="center">{{ data.discountValue || '0' }}</td>
              <!-- 下单时间 -->
              <td nzAlign="center">{{ data.orderTime || '-' }}</td>
              <!-- 付款时间 -->
              <td nzAlign="center">{{ data.payTime || '-' }}</td>
            </tr>
          </tbody>
        </nz-table>
  
        <!-- 分页template -->
        <ng-template #totalTemplate2 let-total>共有 {{ total }} 条</ng-template>
      </div>
    </div>
  </div>
</nz-modal>
<!-- E 直降记录 -->